function sleep (numberMillis) {
  var now = new Date()
  var exitTime = now.getTime() + numberMillis
  while (true) {
    now = new Date()
    if (now.getTime() > exitTime) { return }
  }
}
function test () {
  console.log('script start-' + Date.now())
  setTimeout(function () {
    console.log('setTimeout0-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('setTimeout1-' + Date.now())
  }, 5)
  setTimeout(function () {
    console.log('setTimeout2-' + Date.now())
  }, 55)
  console.log('script start2-' + Date.now())
  // sleep(10000)
  console.log('script start3-' + Date.now())
  new Promise(function (resolve) {
    console.log('promise1 start-' + Date.now())
    resolve()
  }).then(function () {
    console.log('promise1 1-' + Date.now())
  }).then(function () {
    console.log('promise1 2-' + Date.now())
    sleep(5005)
    new Promise(function (resolve) {
      console.log('promise3 start -' + Date.now())
      resolve()
    }).then(function () {
      console.log('promise3-1-' + Date.now())
    }).then(function () {
      console.log('promise3 2-' + Date.now())
    })
    setTimeout(function () {
      console.log('setTimeout3-' + Date.now())
    }, 0)
    setTimeout(function () {
      console.log('setTimeout4-' + Date.now())
    }, 55)
    setTimeout(function () {
      console.log('setTimeout5-' + Date.now())
    }, 50)
    /*
    setTimeout(function () {
      console.log('setTimeout6-' + Date.now())
    }, 48)
    */
  })
  new Promise(function (resolve) {
    console.log('promise2 start-' + Date.now())
    resolve()
  }).then(function () {
    console.log('promise2 1-' + Date.now())
  }).then(function () {
    console.log('promise2 2-' + Date.now())
  })

  setTimeout(function () {
    console.log('setTimeout6-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('setTimeout7-' + Date.now())
  }, 55)
  setTimeout(function () {
    console.log('setTimeout8-' + Date.now())
  }, 50)
  setTimeout(function () {
    console.log('setTimeout9-' + Date.now())
  }, 54)

  console.log('script end-' + Date.now())
}
test()

function test2 () {
  console.log('2script start-' + Date.now())
  setTimeout(function () {
    console.log('2setTimeout 1-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('2setTimeout 2-' + Date.now())
  }, 55)
  console.log('2script start2-' + Date.now())
  new Promise(function (resolve) {
    console.log('2promise1 start-' + Date.now())
    resolve()
  }).then(function () {
    console.log('2promise1 1-' + Date.now())
  }).then(function () {
    console.log('2promise1 2-' + Date.now())
    setTimeout(function () {
      console.log('2setTimeout1 1-' + Date.now())
    }, 0)
    setTimeout(function () {
      console.log('2setTimeout1 2-' + Date.now())
    }, 55)
  })
}
// test2()
function test3 () {
  console.log('script start-' + Date.now())
  setTimeout(function () {
    console.log('setTimeout0-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('setTimeout1-' + Date.now())
    setTimeout(function () {
      console.log('setTimeout10-' + Date.now())
    }, 48)
  }, 5)
  setTimeout(function () {
    console.log('setTimeout2-' + Date.now())
  }, 55)
  setTimeout(function () {
    console.log('setTimeout3-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('setTimeout4-' + Date.now())
  }, 55)
  setTimeout(function () {
    console.log('setTimeout5-' + Date.now())
  }, 50)
  setTimeout(function () {
    console.log('setTimeout6-' + Date.now())
  }, 0)
  setTimeout(function () {
    console.log('setTimeout7-' + Date.now())
  }, 55)
  setTimeout(function () {
    console.log('setTimeout8-' + Date.now())
  }, 50)
  setTimeout(function () {
    console.log('setTimeout9-' + Date.now())
  }, 54)
  console.log('script end-' + Date.now())
}
// test3()
